//
//  AccountInformationVC.m
//  SelfDriving
//
//  Created by apple on 16/1/17.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "AccountInformationVC.h"
#import "BusinessService+User.h"
#import "SetAccountInformationVC.h"
@interface AccountInformationVC ()<SetAccountInformationVCDelegete>
@property (weak, nonatomic) IBOutlet UIButton *isvipBtn;
@property (weak, nonatomic) IBOutlet UIButton *zfbBtn;
@property (weak, nonatomic) IBOutlet UILabel *titleLable;

@end

@implementation AccountInformationVC{
    
}
-(void)viewWillAppear:(BOOL)animated{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[AppDelegate shareDelegate].user.uid forKey:@"fuid"];
    [[BusinessService shareInstance]getUserDetail:dic success:^(id result) {
        [AppDelegate shareDelegate].user = result;
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
    _titleLable.text = [NSString stringWithFormat:@"支付宝账号:%@",[AppDelegate shareDelegate].user.alipay_account];
    if ([[AppDelegate shareDelegate].user.auto_buy_member intValue]==0) {
        _isvipBtn.selected = NO;
    }else{
        _isvipBtn.selected = YES;
    }
    if ([AppDelegate shareDelegate].user.alipay_account.length !=0) {
        [_zfbBtn setTitle:@"取消支付宝账号" forState:UIControlStateNormal];
    }else{
        [_zfbBtn setTitle:@"设置支付宝账号" forState:UIControlStateNormal];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
}
#pragma  mark 是否自动购买会员
- (IBAction)isVipAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
//    [dic setObject:_isvipBtn.selected?@"0":@"1" forKey:@"state"];
    [dic setObject:_isvipBtn.selected?@"1":@"0" forKey:@"state"];
    [SVProgressHUD showWithStatus:@"加载中..."];
    [[BusinessService shareInstance]setAutoBuyMember:dic success:^(id result) {
        [AppDelegate shareDelegate].user = result; //xhw2018-2-28加
        [SVProgressHUD dismiss];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:@"设置是否自动购买会员失败"];
    }];

}

#pragma mark 去设置支付宝界面/或者取消支付宝
- (IBAction)tosetaccoutAction:(UIButton *)sender {
    if([sender.titleLabel.text isEqualToString:@"设置支付宝账号"]){
               UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"GR"
                                                                     bundle:[NSBundle mainBundle]];
        SetAccountInformationVC *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"SetAccountInformationVC"];
        searchResultDetailController.delagete = self;
        [self.navigationController pushViewController:searchResultDetailController animated:YES];
    }else{
        [[BusinessService shareInstance]delAlipayAccount:[[NSMutableDictionary alloc]init] success:^(id result) {
            [SVProgressHUD showSuccessWithStatus:@"取消成功"];
            [_zfbBtn setTitle:@"设置支付宝账号" forState:UIControlStateNormal];
            _titleLable.text = [NSString stringWithFormat:@"请设置支付宝号"];
        } failure:^(id result) {
            [SVProgressHUD showSuccessWithStatus:result];
        }];
    }
}
-(void)delAlipayAccount{
    [_zfbBtn setTitle:@"取消支付宝账号" forState:UIControlStateNormal];
}
- (IBAction)backActino:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
